<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对班长候选人进行投票</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            text-align: center;
        }
        h1 {
            margin-bottom: 20px;
        }
        .options {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
        }
        .option {
            padding: 10px 20px;
            background-color: #f2f2f2;
            border-radius: 5px;
            cursor: pointer;
        }
        .option:hover {
            background-color: #e1e1e1;
        }
        .vote-btn {
            padding: 10px 20px;
            background-color: #008CBA;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .vote-btn:hover {
            background-color: #005f7f;
        }
    </style>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body>
<div class="container">
    <h1>请选择您的投票选项</h1>
    <div class="options">
        <div id="1" class="option" data-vote="option1">张三</div>
        <div id="2" class="option" data-vote="option2">李四</div>
        <div id="3" class="option" data-vote="option3">王五</div>
        <div id="4" class="option" data-vote="option4">赵六</div>
    </div>
<!--    <button class="vote-btn">投票</button>-->
</div>

<script>
    window.onload = function() {
        alert('每人只有4张票');

    }
    class person{
        constructor(name,gender) {
            this.name=name;
            this.gender=gender;
        }

    }
    var count=0;
    p1 = new person("张三",0);
    p2 = new person("李四",0);
    p3 = new person("王五",0);
    p4 = new person("赵六",0);

    document.getElementById('1').onclick = function () {
        count++;
        if(count>3){
            alert("您的票数已经使用完毕，现在退回首页")
            window.location.href = 'index.html';
        }
        axios.put('http://3245465132165.v5.idcfengye.com/users',p1)
            .then(function (response) {
                if (response.data.data) {
                    alert('投票成功');
                } else {
                    alert('投票失败');
                }
            })
    };
    document.getElementById('2').onclick = function () {
        count++;
        if(count>3){
            alert("您的票数已经使用完毕，现在退回首页")
            window.location.href = 'index.html';
        }
        axios.put('http://3245465132165.v5.idcfengye.com/users',p2)
            .then(function (response) {
                if (response.data.data) {
                    alert('投票成功');
                } else {
                    alert('投票失败');
                }
            })
    };
    document.getElementById('3').onclick = function () {
        count++;
        if(count>3){
            alert("您的票数已经使用完毕，现在退回首页")
            window.location.href = 'index.html';
        }
        axios.put('http://3245465132165.v5.idcfengye.com/users',p3)
            .then(function (response) {
                if (response.data.data) {
                    alert('投票成功');
                } else {
                    alert('投票失败');
                }
            })
    };
    document.getElementById('4').onclick = function () {
        count++;
        if(count>3){
            alert("您的票数已经使用完毕，现在退回首页")
            window.location.href = 'index.html';
        }
        axios.put('http://3245465132165.v5.idcfengye.com/users',p4)
            .then(function (response) {
                if (response.data.data) {
                    alert('投票成功');
                } else {
                    alert('投票失败');
                }
            })
    };
</script>
</body>
</html>